'use strict';

angular.module('snPaas_om')
	.controller('ComponentMonitCtrl',['$scope','baseUrl','ngDialog','monitorStore','clusterStore',function($scope,baseUrl,ngDialog,monitorStore,clusterStore){

		var vm = $scope;
		vm.comp = vm.$stateParams.name;
		vm.id = vm.$stateParams.id;
		vm.baseUrl = baseUrl.static;
		vm.isInit = true;
		vm.loading = false;

		clusterStore.detail(vm.id).then(function(data){
			vm.clusterName = data.deploymentName;
			vm.clusterId = vm.id;
		});


		monitorStore.componentMonit(vm.id,vm.comp).then(function(data){
			vm.monitList = data;
		});

		vm.start = function(monit){
			monit.loading = true;
			monitorStore.start(monit.index,vm.comp,vm.clusterId).then(function(){
			monit.loading = false;

				monitorStore.componentMonit(vm.clusterId,vm.comp).then(function(data){
					vm.monitList = data;
				});
			});
		};
		vm.restart = function(monit){
			monit.loading = true;
			monitorStore.restart(monit.index,vm.comp,vm.clusterId).then(function(){
			monit.loading = false;
				monitorStore.componentMonit(vm.clusterId,vm.comp).then(function(data){
					vm.monitList = data;
				});
			});
		};
		vm.stop = function(monit){
			monit.loading = true;
			monitorStore.stop(monit.index,vm.comp,vm.clusterId).then(function(){
			monit.loading = false;
				monitorStore.componentMonit(vm.clusterId,vm.comp).then(function(data){
					vm.monitList = data;
				});
			});
		};
	}]);